package main

import (
	"fmt"
	"sync"
	"time"
)

// go routine 结合 go channel

var wg sync.WaitGroup

func fn1(ch1 chan int) {
	defer wg.Done()
	for i := 0; i < 10; i++ {
		ch1 <- i
		fmt.Println("插入")
		time.Sleep(time.Microsecond * 20)
	}
	close(ch1)
}

func fn2(ch2 chan int) {
	defer wg.Done()
	for v := range ch2 {
		fmt.Println(v)
		time.Sleep(time.Microsecond * 30)
	}
}

func main() {
	var ch = make(chan int, 100)
	wg.Add(2)
	go fn1(ch)

	go fn2(ch)

	wg.Wait()
}
